package com.hao.epidemic_prevention.service;

import com.hao.epidemic_prevention.bean.QueryRangeCondition;
import com.hao.epidemic_prevention.bean.QueryTodayCondition;
import com.hao.epidemic_prevention.bean.User;
import com.hao.epidemic_prevention.bean.UserRecord;
import com.hao.epidemic_prevention.dao.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName UserService
 * @Descroption
 * @Author hao
 * @Date 2021/6/11 16:17
 **/

@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;


    public Boolean addUser(User user) {
        try {
            Integer result = userMapper.addUser(user);

            if(result == 1) return true;
            else return false;
        }
        catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    public User getUser(User user) {
        User result = null;
        try {
            result = userMapper.getUser(user);
        }
        catch (Exception e) {
            e.printStackTrace();
        }

        return result;
    }

    public Integer getUserRecordNumToday() {
        Integer result = 0;
        try {
            result = userMapper.getUserRecordNumToday();
        }
        catch (Exception e) {
            e.printStackTrace();
        }

        return result;
    }

    public Integer getUserNum(QueryRangeCondition condition) {
        Integer result = 0;
        try {
            result = userMapper.getUserNum(condition);
        }
        catch (Exception e) {
            e.printStackTrace();
        }

        return result;
    }

    public List<UserRecord> getUserRecordToday10(QueryTodayCondition condition) {
        List<UserRecord> list = null;

        try {
            condition.setStartNum(condition.getPageLimit() * (condition.getPage() - 1));
            list = userMapper.getUserRecordToday10(condition);
        }
        catch (Exception e) {
            e.printStackTrace();
        }

        return list;
    }
    public List<UserRecord> getUserRecordToday(QueryTodayCondition condition) {
        List<UserRecord> list = null;

        try {
            list = userMapper.getUserRecordToday(condition);
        }
        catch (Exception e) {
            e.printStackTrace();
        }

        return list;
    }
    public List<UserRecord> getUserRecordTodayWithTAsc(QueryTodayCondition condition) {
        List<UserRecord> list = null;

        try {
            list = userMapper.getUserRecordTodayWithTAsc(condition);
        }
        catch (Exception e) {
            e.printStackTrace();
        }

        return list;
    }
    public List<UserRecord> getUserRecordTodayWithTDesc(QueryTodayCondition condition) {
        List<UserRecord> list = null;

        try {
            list = userMapper.getUserRecordTodayWithTDesc(condition);
        }
        catch (Exception e) {
            e.printStackTrace();
        }

        return list;
    }
    public List<User> getNotReportUserToday(QueryRangeCondition condition) {
        List<User> list = null;

        try {
            list = userMapper.getNotReportUserToday(condition);
        }
        catch (Exception e) {
            e.printStackTrace();
        }

        return list;
    }
    public List<UserRecord> getUserRecordRangeWithDAsc(QueryRangeCondition condition) {
        List<UserRecord> list = null;

        try {
            list = userMapper.getUserRecordRangeWithDAsc(condition);
        }
        catch (Exception e) {
            e.printStackTrace();
        }

        return list;
    }
    public List<UserRecord> getUserRecordRangeWithDDesc(QueryRangeCondition condition) {
        List<UserRecord> list = null;

        try {
            list = userMapper.getUserRecordRangeWithDDesc(condition);
        }
        catch (Exception e) {
            e.printStackTrace();
        }

        return list;
    }
    public List<UserRecord> getUserRecordRangeWithTAsc(QueryRangeCondition condition) {
        List<UserRecord> list = null;

        try {
            list = userMapper.getUserRecordRangeWithTAsc(condition);
        }
        catch (Exception e) {
            e.printStackTrace();
        }

        return list;
    }
    public List<UserRecord> getUserRecordRangeWithTDesc(QueryRangeCondition condition) {
        List<UserRecord> list = null;

        try {
            list = userMapper.getUserRecordRangeWithTDesc(condition);
        }
        catch (Exception e) {
            e.printStackTrace();
        }

        return list;
    }
    public List<User> getAllUser() {
        List<User> list = null;
        try {
            list = userMapper.getAllUser();
        }
        catch (Exception e) {
            e.printStackTrace();
        }

        return list;
    }
    public Boolean freezeUser(String userId) {
        Boolean result = false;
        Integer affectRows = 0;
        try {
            affectRows = userMapper.freezeUser(userId);
            if(affectRows == 1) {
                result = true;
            }
        }
        catch (Exception e) {
            e.printStackTrace();
        }

        return result;
    }
    public Boolean unfreezeUser(String userId) {
        Boolean result = false;
        Integer affectRows = 0;
        try {
            affectRows = userMapper.unfreezeUser(userId);
            if(affectRows == 1) {
                result = true;
            }
        }
        catch (Exception e) {
            e.printStackTrace();
        }

        return result;
    }

    public Boolean addUserRecord(UserRecord userRecord) {
        Boolean result = false;
        Integer affectRows = 0;
        try {
            affectRows = userMapper.addUserRecord(userRecord);
            if(affectRows >= 1)result = true;
        }
        catch (Exception e) {
            e.printStackTrace();
        }

        return result;
    }

    public Boolean isReportToday(String roleId) {
        Boolean result = false;
        Integer affectRows = 0;
        try {
            affectRows = userMapper.isReportToday(roleId);
            if(affectRows == 1) result = true;
        }
        catch (Exception e) {
            e.printStackTrace();
        }

        return result;
    }

    public Boolean isFreeze(String roleId) {
        Boolean result = false;
        Integer affectRows = 0;

        try {
            affectRows = userMapper.isFreeze(roleId);
            if(affectRows == 1) {
                result = true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return result;
    }
}
